﻿
SET QUOTED_IDENTIFIER ON
GO

SET ANSI_NULLS ON
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_StaffDimission]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_StaffDimission];
GO
CREATE PROCEDURE [dbo].[sproc_StaffDimission]
    @xml xml,
    @DimissionType bit = 0
/*

============================================================
功能:    员工离职
参数:
    @StaffIDS nvarchar(300)        :    离职员工ID集合
    @DimissionType bit =0        :    离职类型
备注:    @DimissionType bit =0         :    删除标记
    @DimissionType bit = 1         :    永久删除
============================================================

*/
AS
BEGIN
SET NOCOUNT ON

/*
 * XML format:
 * <staffs>
 *  <s id="" />
 * </staffs>
 */
          
if @DimissionType = 1
begin
	delete s from dbo.UDS_Staff s inner join @xml.nodes('/staffs/s') R(x) on s.staff_id = R.x.value('@id', 'int');
end
else
begin
	update s set s.dimission = 1 from dbo.UDS_Staff s inner join @xml.nodes('/staffs/s') R(x) on s.staff_id = R.x.value('@id', 'int');
end

END
GO